//
//  SearchDetailWebVC.m
//  CarHome
//
//  Created by 蒋寒霄 on 14-9-25.
//  Copyright (c) 2014年 WJN_work@163.com. All rights reserved.
//

#import "SearchDetailWebVC.h"

@interface SearchDetailWebVC ()

@end

@implementation SearchDetailWebVC

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
#pragma mark -
#pragma mark viewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createLikeNavigation];
}
#pragma mark -
#pragma mark createLikeNavigation
- (void)createLikeNavigation
{
    UIView *navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 44)];
    navigationView.backgroundColor = myColor_dark;
    [self.view addSubview:navigationView];
    [navigationView release];
    
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    [back setFrame:CGRectMake(10, 5, 30, 30)];
    [back setImage:[UIImage imageNamed:@"BackButton.png"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backToBefore:) forControlEvents:UIControlEventTouchUpInside];
    [navigationView addSubview:back];
}
#pragma mark 创建webview
- (void)setWebUrl:(NSString *)url
{
    _web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64, 320, self.view.frame.size.height - 64)];
    _web.delegate = self;
    [self.view addSubview:_web];
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [_web loadRequest:request];//webView加载网络请求
    [_web release];
}
#pragma mark webViewDelegate
#pragma mark web开始加载
- (void) webViewDidStartLoad:(UIWebView *)webView
{
    //创建UIActivityIndicatorView背底半透明View
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];
    [view setTag:108];
    [view setBackgroundColor:[UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.1]];
    [view setAlpha:0.5];
    [self.view addSubview:view];
    //风火轮的使用
    _activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectZero];
    [_activityIndicator setCenter:view.center];
    [_activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [view addSubview:_activityIndicator];
    [_activityIndicator startAnimating];//开始动作
}
#pragma mark 结束加载
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
    [_activityIndicator stopAnimating];//烽火轮停止
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
    
}
#pragma mark 加载结束有问题
- (void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [_activityIndicator stopAnimating];
    UIView *view = (UIView*)[self.view viewWithTag:108];
    [view removeFromSuperview];
}

#pragma mark -
#pragma mark backbutton函数
- (void)backToBefore:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}
#pragma mark sharebutton函数
- (void)shareTOXinLang:(id)sender
{
    
}
#pragma mark -
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
